package com.ddd.demo.lee.test;

import java.util.Arrays;

public class Solution4 {

    public static void main(String[] args) {
        int[] nums1 = new int[]{1, 3};
        int[] nums2 = new int[]{2, 4};
        double medianSortedArrays = findMedianSortedArrays(nums1, nums2);
        System.out.println("medianSortedArrays = " + medianSortedArrays);
    }

    // 暴力破解
    public static double findMedianSortedArrays(int[] nums1, int[] nums2) {
        int[] merge = new int[nums1.length + nums2.length];
        for (int i = 0; i < nums1.length; i++) {
            merge[i] = nums1[i];
        }
        for (int i = nums1.length; i < nums1.length + nums2.length; i++) {
            merge[i] = nums2[i - nums1.length];
        }

        Arrays.sort(merge);

        double a = merge[merge.length / 2];
        double b = merge[(merge.length - 1) / 2];

        return (a + b) / 2.0;
    }



}
